#include <WebSocket/types.h>
#include "ChatSocket.h"
#include "../ChatConfig.h"

int main()
{
	WS::WebInit();

	ChatConfig config;

	WS::TcpServer::Desc desc;
	desc.port = config.serverPort;

	WS::TcpServer tcpServer;
	if (!tcpServer.Create(desc))
	{
		LOGI("cannot create the server");
		return 0;
	}

	while (1)
	{
		WS::TcpSocket newSocket = tcpServer.Accept();
		LOGI("new client %s %d", newSocket.IP(), newSocket.Port());
		
		ChatSocket *task = new ChatSocket(newSocket);
		task->Start();
	}

	WS::WebClean();
}